﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.ApplicationModel.Resources.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

// The data model defined by this file serves as a representative example of a strongly-typed
// model that supports notification when members are added, removed, or modified.  The property
// names chosen coincide with data bindings in the standard item templates.
//
// Applications may use this model as a starting point and build on it, or discard it entirely and
// replace it with something appropriate to their needs.

namespace WRS.Data
{
    /// <summary>
    /// Base class for <see cref="SampleDataItem"/> and <see cref="SampleDataGroup"/> that
    /// defines properties common to both.
    /// </summary>
    [Windows.Foundation.Metadata.WebHostHidden]
    public abstract class SampleDataCommon : WRS.Common.BindableBase
    {
        public static Uri _baseUri = new Uri("ms-appx:///");

        public SampleDataCommon(String uniqueId, String title,  String imagePath, String description)
        {
            this._uniqueId = uniqueId;
            this._title = title;
            this._imagePath = imagePath;
            this._description = description;
           
        }

        private string _uniqueId = string.Empty;
        public string UniqueId
        {
            get { return this._uniqueId; }
            set { this.SetProperty(ref this._uniqueId, value); }
        }

        private string _title = string.Empty;
        public string Title
        {
            get { return this._title; }
            set { this.SetProperty(ref this._title, value); }
        }

      
        private string _description = string.Empty;
        public string Description
        {
            get { return this._description; }
            set { this.SetProperty(ref this._description, value); }
        }

        private ImageSource _image = null;
        private String _imagePath = null;
        public ImageSource Image
        {
            get
            {
                if (this._image == null && this._imagePath != null)
                {
                    this._image = new BitmapImage(new Uri(SampleDataCommon._baseUri, this._imagePath));
                }
                return this._image;
            }

            set
            {
                this._imagePath = null;
                this.SetProperty(ref this._image, value);
            }
        }

        public void SetImage(String path)
        {
            this._image = null;
            this._imagePath = path;
            this.OnPropertyChanged("Image");
        }
    }

    /// <summary>
    /// Generic item data model.
    /// </summary>
    public class SampleDataItem : SampleDataCommon
    {
        public SampleDataItem(String uniqueId, String title, String imagePath, String description,  SampleDataGroup group)
            : base(uniqueId, title, imagePath, description)
        {
          

            this._group = group;
        }

       
         private SampleDataGroup _group;
        public SampleDataGroup Group
        {
            get { return this._group; }
            set { this.SetProperty(ref this._group, value); }
        }
       
    }

    /// <summary>
    /// Generic group data model.
    /// </summary>
    public class SampleDataGroup : SampleDataCommon
    {
        public SampleDataGroup(String uniqueId, String title, String imagePath, String description)
            : base(uniqueId, title,  imagePath, description)
        {
           
        }
     
        private ObservableCollection<SampleDataItem> _items = new ObservableCollection<SampleDataItem>();
        public ObservableCollection<SampleDataItem> Items
        {
            get { return this._items; }
        }
    }

    /// <summary>
    /// Creates a collection of groups and items with hard-coded content.
    /// </summary>
    public sealed class SampleDataSource 
    {
        private ObservableCollection<SampleDataGroup> _itemGroups = new ObservableCollection<SampleDataGroup>();
        public ObservableCollection<SampleDataGroup> ItemGroups
        {
            get { return this._itemGroups; }
        }

        public SampleDataSource()
        {
            String AnimalSubtitle = String.Format("Test");

            var group1 = new SampleDataGroup("Group-1",
                "Animals",

                "Assets/Animal.png",
                "Test1");
            group1.Items.Add(new SampleDataItem("Group-1-Item-1",
                "Noon",

                "Assets/RWS/level1.png",

                AnimalSubtitle,
                group1));
            group1.Items.Add(new SampleDataItem("Group-1-Item-2",
              "Noon",

              "Assets/RWS/locklevel2.png",

              AnimalSubtitle,
              group1));
            group1.Items.Add(new SampleDataItem("Group-1-Item-3",
              "Noon",

              "Assets/RWS/locklevel3.png",

              AnimalSubtitle,
              group1));
            group1.Items.Add(new SampleDataItem("Group-1-Item-4",
              "Noon",

              "Assets/RWS/locklevel4.png",

              AnimalSubtitle,
              group1));
            this.ItemGroups.Add(group1);

            var group2 = new SampleDataGroup("Group-2",
               "Sports",

               "Assets/Sport.png",
               "Test1");
            group2.Items.Add(new SampleDataItem("Group-2-Item-1",
               "Noon",

               "Assets/RWS/level1.png",

               AnimalSubtitle,
               group2));
            group2.Items.Add(new SampleDataItem("Group-2-Item-2",
              "Noon",

              "Assets/RWS/locklevel2.png",

              AnimalSubtitle,
              group2));
            group2.Items.Add(new SampleDataItem("Group-2-Item-3",
              "Noon",

              "Assets/RWS/locklevel3.png",

              AnimalSubtitle,
              group2));
            group2.Items.Add(new SampleDataItem("Group-2-Item-4",
              "Noon",

              "Assets/RWS/locklevel4.png",

              AnimalSubtitle,
              group2));
            this.ItemGroups.Add(group2);

        }
    }
}
